package com.zjlanyun.erp.interior.warehouse;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zjlanyun.erp.R;

import java.util.List;

/**
 * @author: shun
 * @date: 2016-12-19 8:59
 * @Desc:
 */

public class InventoryAdapter extends BaseAdapter {

    private List<InventoryModel.ListBean> mList;
    private LayoutInflater mInflater;

    public final class ListItemView {
        public TextView sort;
        public TextView fnumber;
        public TextView fname;
        public TextView fqty;
        public TextView fclqty;
        public TextView fgongxuname;
        public TextView fposition;
    }

    public InventoryAdapter(Context context, List<InventoryModel.ListBean> mList) {
        this.mInflater = LayoutInflater.from(context);
        this.mList = mList;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ListItemView listItemView = null;
        if (convertView == null) {
            listItemView = new ListItemView();
            convertView = mInflater.inflate(R.layout.inventory_item, null);
            listItemView.sort = (TextView) convertView.findViewById(R.id.tv_sort);
            listItemView.fnumber = (TextView) convertView.findViewById(R.id.tv_fnumber);
            listItemView.fname = (TextView) convertView.findViewById(R.id.tv_fname);
            listItemView.fqty = (TextView) convertView.findViewById(R.id.tv_fqty);
            listItemView.fclqty = (TextView) convertView.findViewById(R.id.tv_fclqty);
            listItemView.fgongxuname = (TextView) convertView.findViewById(R.id.tv_fgongxuname);
            listItemView.fposition = (TextView) convertView.findViewById(R.id.tv_fposition);
            convertView.setTag(listItemView);
        } else {
            listItemView = (ListItemView) convertView.getTag();
        }
        listItemView.sort.setText(String.valueOf(position + 1) + "、");
        listItemView.fnumber.setText("物料代码："+mList.get(position).getFNumber());
        listItemView.fname.setText(mList.get(position).getFName());
        listItemView.fqty.setText("米数："+String.valueOf(mList.get(position).getFQty()));
        listItemView.fclqty.setText("材料数量："+String.valueOf(mList.get(position).getFCLQty()));
        listItemView.fgongxuname.setText("工序："+mList.get(position).getFGongxuName());
        listItemView.fposition.setText("位置："+mList.get(position).getFPosition());
        return convertView;
    }
}
